using System;
using Picnic.Spec.Exceptions;

namespace Picnic.Spec
{
	/// <summary>
	/// Represents a result of statement validation.
	/// </summary>
	public class StatementValidationResult
	{
		private readonly TimeSpan _elapsed;
		private readonly Exception _error;

		/// <summary>
		/// Initializes a new instance of the <see cref="StatementValidationResult"/> class.
		/// </summary>
		public StatementValidationResult(TimeSpan elapsed, Exception error)
		{
			_elapsed = elapsed;
			_error = error;
		}

		/// <summary>
		/// Gets a time elapsed for statement validation.
		/// </summary>
		public TimeSpan Elapsed
		{
			get { return _elapsed; }
		}

		/// <summary>
		/// Gets a statement validation result kind.
		/// </summary>
		public StatementValidationResultKind Kind
		{
			get
			{
				if (_error == null)
				{
					return StatementValidationResultKind.Satisfied;
				}
				if (_error is PassStatementException)
				{
					return StatementValidationResultKind.Passed;
				}
				return StatementValidationResultKind.Failed;
			}
		}

		/// <summary>
		/// Gets a statement validation error. If statement is valid, returns <see langword="null"/>.
		/// </summary>
		public Exception Error
		{
			get { return _error; }
		}
	}
}